﻿using Crgd.UAuthServer.T4.Entities;
using Crgd.UAuthServer.T4.Helpers;
using DreamX.T4.Entities;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Schema;

namespace Crgd.UAuthServer.T4.Configs
{
    /// <summary>
    /// T4 代码生成配置类
    /// </summary>
    public sealed class T4Config
    {
        public T4Config()
        {
            //this.GenTablesWithMoudle.Count
        }
        /// <summary>
        /// 命名空间
        /// </summary>
        public string ProjectName { get; set; }

        /// <summary>
        /// 数据库上下文名称
        /// </summary>
        public string DbContextName { get; set; }

        /// <summary>
        /// 表前缀
        /// </summary>
        public string TablePrefix { get; set; }

        /// <summary>
        /// 是否删除表名称前缀，主要影响生成模型的类名
        /// </summary>
        public bool IsDeleteTablePrefix { get; set; }

        /// <summary>
        /// 列前缀
        /// </summary>
        public string ColumnPrefix { get; set; }

        /// <summary>
        /// 是否删除数据列名称前缀，主要影响生成模型的属性名
        /// </summary>
        public bool IsDeleteColumnPrefix { get; set; }

        public string ConfigPath { get; set; }

        public string EntityPath { get; set; }

        public string DtoPath { get; set; }

        /// <summary>
        /// 文件输出根路径
        /// </summary>
        public string GenerateRootPath { get; set; }

        /// <summary>
        /// 数据库配置信息
        /// </summary>
        public DbConfig DbConfig { get; set; }

        /// <summary>
        /// 获取或设置 需要生成的数据表列表，为空时时生成所有, Key 为模块名称
        /// </summary>
        public Dictionary<string, IList<string>> GenTablesWithMoudle { get; set; }

        /// <summary>
        /// 获取或设置 不需要自动生成代码的表名称
        /// </summary>
        public IList<string> DeclaredTableNames { get; set; }

        /// <summary>
        /// 设置或获取 已申明的枚举类型，该类型在生成代码时，将不再进行申明，直接进行引用
        /// </summary>
        public IList<string> DeclaredEnumTypes { get; set; }

        /// <summary>
        /// 自动生成代码版权信息
        /// </summary>
        public CopyRightConfig CopyRight { get; set; }

        /// <summary>
        /// 模块名称类型
        /// </summary>
        public MoudleNameType MoudleNameType { get; set; }
        
        /// <summary>
        /// 根据 JSON 配置文件构建配置对象
        /// </summary>
        /// <param name="fullFileName">json 文件全路径</param>
        /// <returns></returns>
        public static T4Config BuildConfig(string fullFileName)
        {
            var configJson = System.IO.File.ReadAllText(fullFileName);
            return JsonConvert.DeserializeObject<T4Config>(configJson);
        }
    }
}
